package com.platform.modules.mall.activityV2.restrict;

import com.platform.modules.mall.activity.entity.bo.ActivityGoshoppingBo;
import com.platform.modules.mall.activityV2.entity.ParticipantBo;
import com.platform.modules.mall.entity.MallActivityEntity;
import com.platform.modules.mall.entity.MallGoodsToActivityEntity;
import com.platform.modules.mall.service.MallGoodsToActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 不做任何的限制，所有的人都可以参加活动购买商品
 */
@Component("noRestrict")
public class NoRestrict implements RestrictInterfaceV2{

    @Autowired
    private MallGoodsToActivityService mallGoodsToActivityService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ParticipantBo restrict(ActivityGoshoppingBo bo, MallActivityEntity mallActivityEntity) {
        return myRestrict(bo,mallActivityEntity);
    }

    @Override
    public ParticipantBo restrictQuery(ActivityGoshoppingBo bo, MallActivityEntity mallActivityEntity) {
        return myRestrict(bo,mallActivityEntity);
    }

    /**
     * 默认给可以领取99个，每次都是一样的，可以一直购买，没有任何的限制
     *
     * @param bo
     * @param mallActivityEntity
     * @return
     */
    private ParticipantBo myRestrict(ActivityGoshoppingBo bo, MallActivityEntity mallActivityEntity){

        Map<String, Object> params =new HashMap<>();
        params.put("activityId", bo.getActivityId());
        params.put("isDelete",1);
        params.put("isOnSale",1);
        params.put("orderbySort"," order by T.SORT ");
        List<MallGoodsToActivityEntity> list = mallGoodsToActivityService.queryAll(params);

        ParticipantBo participantBo =new ParticipantBo();
        participantBo.setNum(99);
        participantBo.setList(list);
        participantBo.setGoodsId(bo.getGoodsId());
//        participantBo.setActivityType(mallActivityEntity.getActivityType());
        return participantBo;
    }
}
